'''
该程序说明：在 Shell 中显示 ADC 的值
在线文档：https://docs.geeksman.com/esp32/MicroPython/22.esp32-micropython-ps2.html
'''
import time
from machine import Pin, ADC
from machine import SoftI2C 
from ssd1306 import SSD1306_I2C

# 定义摇杆引脚
ps2_x = ADC(Pin(2), atten=ADC.ATTN_11DB)
ps2_y = ADC(Pin(4), atten=ADC.ATTN_11DB)
ps2_button = Pin(5, Pin.IN)


# 定义对应的管脚对象
i2c = SoftI2C(sda=Pin(13), scl=Pin(14))
oled = SSD1306_I2C(128, 32, i2c )
 



while True:
    print(f'x:{ps2_x.read()},y:{ps2_y.read()},z:{ps2_button.value()}')
    # 清屏
    oled.fill(0)
    # 打印 Hello world 在屏幕上
    oled.text("X:"+str(ps2_x.read()),10, 0)
    oled.text("Y:"+str(ps2_y.read()),10, 20)
    # 显示内容
    oled.show()

    time.sleep(0.1)